package com.admin.vo;

import com.admin.common.enums.EnumResult;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ApiModel(value = "返回说明")
public class ResultEntity<T> {

    /* 错误码 */
    @ApiModelProperty(value = "状态码：0成功 !0失败")
    private Integer Code;

    /* 提示信息 */
    @ApiModelProperty(value = "提示信息")
    private String Msg;

    /* 具体内容 */
    @ApiModelProperty(value = "数据")
    private T data;

    public ResultEntity() {
    }

    public ResultEntity(Integer code, String msg) {
        Code = code;
        Msg = msg;
    }

    public ResultEntity(Integer code, String msg, T data) {
        this.Code = code;
        this.Msg = msg;
        this.data = data;
    }

    public static <T> ResultEntity<T> ok(T t) {
        ResultEntity<T> r = new ResultEntity<T>();
        r.setCode(EnumResult.SUCCESS.getCode());
        r.setMsg(EnumResult.SUCCESS.getMsg());
        r.setData(t);
        return r;
    }

    public static <T> ResultEntity<T> ok() {
        ResultEntity<T> r = new ResultEntity<T>();
        r.setCode(EnumResult.SUCCESS.getCode());
        r.setMsg(EnumResult.SUCCESS.getMsg());
        r.setData(null);
        return r;
    }

    public static <T> ResultEntity<T> error(String message) {
        ResultEntity<T> r = new ResultEntity<T>();
        r.setCode(-1);
        r.setMsg(message);
        r.setData(null);
        return r;
    }


    public static <T> ResultEntity<T> error(ResultEnum resultEnum) {
        ResultEntity<T> r = new ResultEntity<T>();
        r.setCode(resultEnum.getCode());
        r.setMsg(resultEnum.getMsg());
        r.setData(null);
        return r;
    }

    public ResultEntity(ResultEnum resultEnum) {
        this.Code = resultEnum.getCode();
        this.Msg = resultEnum.getMsg();
    }

    public ResultEntity(String msg) {
        this.Code = ResultEnum.PARAMETER_MISMATCH.getCode();
        this.Msg = msg;
    }


    public Integer getCode() {
        return Code;
    }

    public void setCode(Integer code) {
        Code = code;
    }

    public String getMsg() {
        return Msg;
    }

    public void setMsg(String msg) {
        Msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
